package com.asa.common.widgets;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.View;

/**
 * Author: Lixiaoge
 * Date: 2019/12/4
 * Description:按钮文字点击动画
 */
public class NewButtonAnim {

    public static AnimatorSet loadDownAnim(View view) {
        return loadDownAnim(view, true);
    }

    public static AnimatorSet loadUpAnim(View view) {
        return loadUpAnim(view, true);
    }

    public static AnimatorSet loadDownAnim(View view, Boolean useAlpha) {
        AnimatorSet animatorSet = new AnimatorSet();
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1.0f, 0.95f);
        scaleX.setDuration(200);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1.0f, 0.95f);
        scaleY.setDuration(200);
        ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 1.0f, 0.7f);

        animatorSet.setInterpolator(new CubicBezierInterpolator(0.33f, 0f, 0f, 1f));
        if (useAlpha) {
            animatorSet.play(scaleX).with(scaleY).with(alpha);
        } else {
            animatorSet.play(scaleX).with(scaleY);
        }
        return animatorSet;
    }

    public static AnimatorSet loadUpAnim(View view, Boolean useAlpha) {
        AnimatorSet animatorSet = new AnimatorSet();
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 0.95f, 1.0f);
        scaleX.setDuration(400);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 0.95f, 1.0f);
        scaleY.setDuration(400);
        ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 0.7f, 1.0f);

        animatorSet.setInterpolator(new CubicBezierInterpolator(0.33f, 0f, 0f, 1f));
        if (useAlpha) {
            animatorSet.play(scaleX).with(scaleY).with(alpha);
        } else {
            animatorSet.play(scaleX).with(scaleY);
        }
        return animatorSet;
    }

    public static AnimatorSet loadScaleAnim(View view, Boolean useAlpha) {
        AnimatorSet animatorSet = new AnimatorSet();

        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.9f, 1.0f);
        scaleX.setDuration(300);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.9f, 1.0f);
        scaleY.setDuration(300);
        ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 0.7f, 1.0f);

        animatorSet.setInterpolator(new CubicBezierInterpolator(0.33f, 0f, 0f, 1f));
        if (useAlpha) {
            animatorSet.play(scaleX).with(scaleY).with(alpha);
        } else {
            animatorSet.play(scaleX).with(scaleY);
        }
        return animatorSet;
    }

}
